home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 10332 < prev    next >
Encoding:
Text File  |  1996-08-05  |  5.9 KB  |  250 lines

  1. Path: newsbf02.news.aol.com!not-for-mail
  2. From: djmintz@aol.com (DJMintz)
  3. Newsgroups: comp.lang.c++
  4. Subject: HELP!!! Syntax error!
  5. Date: 7 Mar 1996 10:13:52 -0500
  6. Organization: America Online, Inc. (1-800-827-6364)
  7. Sender: root@newsbf02.news.aol.com
  8. Message-ID: <4hmufg$7fq@newsbf02.news.aol.com>
  9. Reply-To: djmintz@aol.com (DJMintz)
  10. NNTP-Posting-Host: newsbf02.mail.aol.com
  11.  
  12. Okay, here is the code I am trying to compile. The error I am getting is:
  13. Error fade.c 44: ) expected. Here is the code. Please see if you can fix
  14. it:
  15.  
  16. /* Portions of this program are based on the book "Bit-Mapped-Graphics" by
  17.  
  18. Steve Rimmer. excelent book for learning picture formats.  Way too fluffy
  19. in 
  20. places way too technical others pretty decent overall though.  Once       
  21.       
  22. you understand the program, try fading from one screen into another
  23. directly.
  24. */
  25.  
  26. #include <stdio.h>
  27. #include <alloc.h>
  28. #include <dos.h>
  29.  
  30.  
  31. typedef struct {
  32.     char    manufacturer;
  33.     char    version;
  34.     char    encoding;
  35.     char    bits_per_pixel;
  36.     int     xmin,ymin;
  37.     int     xmax,ymax;
  38.     int     hres;
  39.     int     vres;
  40.     char    pallete[48];
  41.     char    reserved;
  42.     char    colour_planes;
  43.     int     bytes_per_line;
  44.     int     pallete_type;
  45.     char    filler[58];
  46.         } PCXHEAD;
  47. PCXHEAD   header;
  48. /* The variable header is a struct that will contain all the usefull
  49. picture
  50. information shown in the above fields.  */
  51. unsigned int width,depth;    /* will hold the header info for width and
  52. depth*/
  53. unsigned int bytes;
  54.  
  55. char palette[768];
  56.  
  57. void deinit(void);/* return to normal           */
  58. void setVGApalette(char *p); /*set the vga pallete   */
  59. void ReadBuffer_A(FILE *fp,char *buffer);
  60. FILE *open_pic(char *filename);
  61.  
  62.  
  63. typedef int counter_type;
  64.  
  65. main(argc,*argv[])     < ---- ERROR OCCURS HERE, ON LINE 44! Please help!
  66. {
  67.  
  68.         int argc;
  69.            char *argv[];
  70.         int     c;
  71.            FILE *input;
  72.            char *buffer;
  73.            counter_type   temparg=0;
  74.     
  75.    if(argc > 1)
  76.     {
  77.         for(temparg=1; temparg<argc; temparg++)
  78.     {
  79.        input = open_pic(argv[temparg]);
  80.        if (input != NULL){
  81.         if((buffer = (char *) malloc(64000)) == NULL){
  82.             printf("not enough memory to perform read
  83. operation");
  84.         }
  85.     /* initialize vgamode 320x200 in 256 color mode                   
  86.    */
  87.     asm{
  88.        mov ax,13h
  89.        int 10h
  90.        };
  91.           setVGApalette(palette);        
  92.           ReadBuffer_A(input,buffer);
  93.           fclose(input);
  94.           free(buffer);}
  95.      else exit(1);
  96.      }
  97.     }
  98. deinit();
  99. return 0;
  100. }
  101.  
  102. FILE  *open_pic(char *filename)
  103. {
  104.  
  105.     FILE *fp;
  106.  
  107.     if((fp=fopen(filename,"rb")) != NULL){
  108.             /* read in the header */
  109.          if(fread((char *) &header,1,sizeof(PCXHEAD),fp)
  110.          == sizeof(PCXHEAD)){
  111.          /*check to make sure it's a picture */
  112.            if(header.manufacturer==0x0a &&
  113.               header.version ==5){
  114.  
  115.             if(!fseek(fp,-769L,SEEK_END)){
  116.                if(fgetc(fp) == 0x0c &&
  117.                 fread(palette,1,768,fp) == 768) {
  118.                   fseek(fp,128L,SEEK_SET);
  119.                   /*allocate a big buffer */
  120.                 width = (header.xmax -
  121.                 header.xmin) +1;
  122.                 depth = (header.ymax-
  123.                 header.ymin)+1;
  124.                 bytes=header.bytes_per_line;
  125.                     } else
  126.             puts("error reading pallete");
  127.         }else puts ("error seeking to pallete");
  128.     }else printf("not a 256 color pcx file.\n");
  129.      }else printf("error reading %s.\n",filename);
  130. /*  fclose(fp); */
  131.  } else printf ("Error opening %s.\n",filename);
  132.  
  133. return fp;
  134. }
  135.  
  136.  
  137. void  ReadBuffer_A(FILE *fp, char *buffer)
  138. {
  139.     char *p;
  140.     int size,x,c,count;
  141.     long int n;
  142.     long int i=0;
  143.     long int   inc;
  144.     c=0;
  145.     p = MK_FP(0xa000,0);   /* MAKE P, A POINTER TO THE VIDEO SCREEN */
  146. /* THE PCX INFORMATION IS STORED IN A SOMEWHAT PACKED FORMAT, IF THERE ARE
  147.         
  148. 50 PIXELS OF BLACK THEN THE PCX FILE WILL CONTAIN THE NUMBER 50 FOLLOWED
  149. BY THE 
  150. PIXEL INFORMATION FOR THE COLOR BLACK. THIS LOOP INTERPRETS AND UNPACKS
  151. THAT
  152. DATA                                                            */
  153.     for (i=0;i<64000;++i){
  154.         c=fgetc(fp) & 0xff;  /* if it's a run of bytes field */
  155.  
  156.         if((c & 0xc0) == 0xc0) { /* and off the high bits */
  157.             x=c & 0x3f;
  158.             /* run the byte */
  159.             c=fgetc(fp);
  160.             while(x--) buffer[i++]=c;
  161.             i--;
  162.             }
  163.             /*else just store it */
  164.             else buffer[i]=c;
  165.         }
  166.  
  167.       
  168. /* iterate the random number routine 80,000 times to get as much fade in
  169. as
  170. possible and to slow it down a little.  If you notice the i+=32000        
  171.                    
  172. That's because the Rand() function only returns a number in the range of
  173. 2exp15 -1
  174. so we actually draw two dots onto the screen at a time, 1 in the upper
  175. half
  176. of the screen, and 1 in the lower half.  The effect is still good       */
  177. for(n=0; n <120000 ; n++){        
  178.          i = (rand() % 32000);  
  179.          p[i] = buffer[i];
  180.          i+=32000;
  181.          p[i]=buffer[i];
  182.         
  183.     }         
  184. /* once the for loop is done there will still be about 30-40 dots left
  185. undone
  186. at this point we just copy the entire buffer onto screen which effectively
  187. fills
  188. these dots in.                                                          */
  189. memcpy(p,buffer,64000); /*COPY 64000 POSITIONS OF BUFFER ONTO THE SCREEN
  190. */
  191.  
  192. /*0 out the buffer for a fade-out                                       */
  193.  
  194. memset(buffer,0,64000); /*COPY 0 INTO 64000 POSITIONS OF THE BUFFER */
  195.  
  196. /* add a delay loop so we can see the screen for a sec before we fade-out
  197. */
  198. for(n=0; n < 120000;n++){
  199.     for(i=0;i < 10;i++);};
  200. /*  Same principle as above---fade-out                                  */
  201. for(n=0; n <120000 ; n++){        
  202.          i = (rand() % 32000);  
  203.          p[i] = buffer[i];
  204.          i+=32000;
  205.          p[i]=buffer[i];
  206.         
  207.   }         
  208. memcpy(p,buffer,64000);         
  209.  
  210. }
  211.  
  212.  
  213.  
  214.  
  215. void  deinit(void)   /*turn off graphics card */
  216. {
  217.      asm{
  218.     mov ax,3h
  219.     int 10h
  220.     };
  221.  
  222. }
  223.  
  224. void setVGApalette(char *p)   /*set the VGA palette to RGB buffer p */
  225.  
  226. {
  227.     union REGS r;
  228.     struct SREGS sr;
  229.     int i;
  230.  
  231.     /* convert eight bits to six bits */
  232.     for (i=0;i<768;i++) p[i]=p[i] >> 2;
  233.  
  234.     r.x.ax=0x1012;
  235.     r.x.bx=0;
  236.     r.x.cx=256;
  237.     r.x.dx=FP_OFF(p);
  238.     sr.es=FP_SEG(p);
  239.     int86x(0x10,&r,&r,&sr);
  240. }
  241.  
  242.  
  243.  
  244.  
  245.  
  246. Well, thanks anybody for any time you spend on this! Please help! Either
  247. e-mail me directly or post a message in reply to this one. Thanks!
  248.  
  249. Dan
  250.